package work;

/**
 * @TODO
 * @Author xu
 * 2025/2/24
 */
import java.util.Scanner;
public class Day3_8 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.println("请输入一个不小于6的偶数，输入0表示退出：");

        while (true) {
            int evenNumber = scanner.nextInt();
            if (evenNumber == 0) {
                System.out.println("退出程序。");
                break;
            }
            if (evenNumber < 6 || evenNumber % 2 != 0) {
                System.out.println("请输入一个不小于6的偶数。");
                continue;
            }
            if (canExpressAsSumOfTwoOddPrimes(evenNumber)) {
                System.out.println(evenNumber + " 可以表示为两个奇素数之和。");
            } else {
                System.out.println(evenNumber + " 不能表示为两个奇素数之和。");
            }
        }

    }

    private static boolean isPrime(int num) {
        if (num <= 1) return false;
        for (int i = 2; i <= Math.sqrt(num); i++) {
            if (num % i == 0) return false;
        }
        return true;
    }

    private static boolean canExpressAsSumOfTwoOddPrimes(int evenNumber) {
        for (int i = 3; i <= evenNumber / 2; i += 2) {
            if (isPrime(i) && isPrime(evenNumber - i)) {
                System.out.println(evenNumber + " = " + i + " + " + (evenNumber - i));
                return true;
            }
        }
        return false;
    }

}
